package cn.xiaobai.service.impl;

import cn.xiaobai.service.DataPerceptionService;
import cn.xiaobai.monitor.MonitorServer;
import cn.xioabai.common.utility.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Optional;

/**
 * websocket 服务端感知实现
 *
 * @Author yangdaji
 * @Date 2022/11/10
 * @PackageName xiaobai.service.impl.websocket
 * @ClassName WebsocketPerceptionServiceImpl
 */
@Service
public class PerceptionServiceImpl implements DataPerceptionService {


    @Autowired
    private MonitorServer monitorServer;

    @Override
    public Optional<String> queryPushDataByChannel(String channel) {
        //获取推送数据
        Map<String, Object> channelToDataMap = monitorServer.getChannelToDataMap();
        Object jsonData = channelToDataMap.get(channel);
        String jsonMessage = JsonUtils.toJsonStr(jsonData);
        return Optional.ofNullable(jsonMessage);
    }
}
